<?php
class EbookManager extends ObjectManager {
	public function addObject($object) {
		global $db;
		$name = $db->real_escape_string ( $object ['name'] );
// 		echo 'Name:'.$name;
		$desc = $db->real_escape_string ( $object ['desc'] );
// 		echo 'Description:'.$desc;
		$image_link = $db->real_escape_string ( $object ['image_link'] );
// 		echo 'Image link:'.$image_link;
		$year = $db->real_escape_string ( $object ['year'] );
// 		echo 'Year:'.$year;
		$download_link = $db->real_escape_string ( $object ['download_link'] );
// 		echo 'Download Link:'.$download_link;
		$query = "INSERT INTO tbl_Ebook (name, descirption, image_link, `year_publish`, `download_link`) 
				VALUES('" . $name . "','". $desc . "','" . $image_link . "'," . $year . ",'" . $download_link . "')";
// 		echo $query;
		$result = $db->query ( $query ) or die ( $db->error );
		if ($result) {
			return true;
		} else {
			return false;
		}
	}
    
	public function getObjects() {
		global $db;
		$query="select * from tbl_Ebook";
		$result=mysqli_query($db, $query);
		// 		echo mysqli_num_rows($result);
		return $result;
	}
	
	public function deleteObject($id){
		global $db;
		$query="delete from tbl_Ebook where id_ebook=".$id;
		$result=mysqli_query($db, $query);
		if($result){
			return true;
		}else return false;
	}
	public function updateObject($object){
		
	}
	public function check($id){
		global $db;
		$query="select * from tbl_Ebook where id_ebook='".$id."'";
		$result=mysqli_query($db, $query);
		return $result;
	}
	public function findObjectsByText($text){
		global $db;
		$query="select * from tbl_Ebook where name like '%".$text."%'";
		$result=mysqli_query($db, $query);
		return $result;
	}
	public function findObjectByYear($year){
	    global $db;
	    $query="select * from tbl_Ebook where year_publish like ".$year;
	    $result=mysqli_query($db,$query);
	    return $result;
	}
	public function findObjectByDescription($desc){
	    global $db;
	    $query="query * from tbl_Ebook where descirption like '%".$desc."%'";
	    $result=mysqli_query($db,$query);
	    return $result;
	}
	public function getObjectsSort($column, $type){
		
	}
	public function getFollowEbook($limit){
	    global $db; 
	    $query="select * from tbl_Ebook order by name desc limit 0,".$limit;
	    $result=mysqli_query($db,$query);
	    return $result;
	}	
}

